package pear.gui.table;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.io.Console;
import javax.swing.BorderFactory;
import javax.swing.JProgressBar;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableModel;

/**
 *
 * @author Dingo
 */
public class ProgressBarCellRenderer extends JProgressBar implements TableCellRenderer {

    public ProgressBarCellRenderer() {
        super(0, 100);
        setFont(new Font("SansSerif", 0, 10));
        setValue(0);
        setString("0%");
        setStringPainted(true);
        setOpaque(true);
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        if (isSelected) {
            setForeground(table.getSelectionForeground());
            setBackground(table.getSelectionBackground());
        } else {
            setForeground(table.getForeground());
            if (row % 2 == 1) {
                setBackground(table.getBackground());
            } else {
                setBackground(Color.WHITE);
            }
        }
        int intValue = (Integer) (value);
        setValue(intValue);
        setString(intValue + "%");
        return this;
    }
}
